package com.ky.tms.controller;


import com.ky.tms.entity.TmsExpense;
import com.ky.tms.service.ITmsExpenseService;
import com.ky.tms.util.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chengkaimao
 * @since 2020-05-07
 */
@RestController
@RequestMapping("/tms/tms-expense")
public class TmsExpenseController {


    @Autowired
    private ITmsExpenseService tmsExpenseService;

    @ApiOperation("报销费用分页数据")
    @GetMapping("page")
    public CommonResult page(TmsExpense tmsExpense, @RequestParam Long pageSize, @RequestParam Long current) {
        return CommonResult.buildSuccess(tmsExpenseService.page(tmsExpense,pageSize, current));
    }

    @ApiOperation("创建报销费用")
    @PostMapping
    public CommonResult add(@RequestBody TmsExpense tmsExpense){
        tmsExpenseService.add(tmsExpense);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("修改报销费用")
    @PutMapping
    public CommonResult update(@RequestBody TmsExpense tmsExpense){
        tmsExpenseService.update(tmsExpense);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("更新状态")
    @PutMapping("status/{status}")
    public CommonResult updateStatus(@RequestBody List<Long> ids, @PathVariable("status") String status){
        tmsExpenseService.updateStatus(ids, status);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("删除报销费用")
    @DeleteMapping
    public CommonResult delete(@RequestBody List<Long> ids){
        tmsExpenseService.delete(ids);
        return CommonResult.buildSuccess(null);
    }

}
